package com.example.waimai004.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.waimai004.entity.Employee;
import com.example.waimai004.entity.Grate;
import com.example.waimai004.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@Controller+@ResponseBody=@RestController
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    /***
     * 查询employee表的全部数据
     */
    @PostMapping ("/getList")
    public List<Employee> getList(){
        return employeeService.list();
    }
    @GetMapping("/getById/{id}")
    public Employee getById(@PathVariable("id") Integer id){
//                employeeService.
        return employeeService.getById(id);
    }
    @GetMapping("/getByPhone")
    public List<Employee> getByPhone(){
//        1.实例化条件构造器
        LambdaQueryWrapper<Employee/*对其操作的类型*/> wrapper=new LambdaQueryWrapper<>();
//        2.添加条件 select * from employee where phone like '%237%'
//        wrapper.条件的关键字（获取表中字段的名字.字段对应的值
//        Employee::getPhone =====>phone
        wrapper.like(Employee::getPhone,"237");
//        3.调用查询方法
        return employeeService.list(wrapper);
    }


//    eq等于 ne不等于 gt大于 li小于
    @GetMapping("/getBySex")
    public List<Employee> getBySex(){
        LambdaQueryWrapper<Employee> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Employee::getSex ,1).orderByDesc(Employee::getId);
        return employeeService.list(wrapper);
    }

}
